package com.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.InvitationMapper;
import com.mapper.ReplyDetailMapper;
import com.pojo.Invitation;
import com.pojo.ReplyDetail;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Aiden
 * @version 1.0
 * @description
 * @date 2019-12-11 13:03:19
 */
@Service
public class ServiceInterfaceImpl implements ServiceInterface {
    @Autowired
    InvitationMapper invitationMapper;
    @Autowired
    ReplyDetailMapper replyDetailMapper;
    @Override
    public PageInfo findAllInvitation(String title, Integer pageNum, Integer pageSize) {
        //开启分页
        PageHelper.startPage(pageNum, 3);
        //模糊查询所有的帖子
        List<Invitation> invitationList = invitationMapper.queryAllInvitation(title);
        //封装
        PageInfo pageInfo = new PageInfo(invitationList);
        return pageInfo;
    }

    @Override
    public PageInfo findAllReplyDetail(Integer invid, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, 3);
        List<ReplyDetail> replyDetailList = replyDetailMapper.queryByInvid(invid);
        PageInfo pageInfo = new PageInfo(replyDetailList);
        return pageInfo;
    }

  /*  @Override
    public List<ReplyDetail> findAllReplyDetail(Integer invid) {
        List<ReplyDetail> replyDetail = replyDetailMapper.queryByInvid(invid);
        return replyDetail;
    }*/

    @Override
    public boolean addReply(ReplyDetail replyDetail) {
        int i = replyDetailMapper.insert(replyDetail);
        return i>0;
    }

    @Override
    public boolean removeInvitationAndReply(Integer id) {
        boolean b = replyDetailMapper.deleteReply(id);
        int i = invitationMapper.deleteByPrimaryKey(id);
        if( i>0){
            return true;
        }else
        return false;
    }
}
